package com.smart.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smart.common.PageInfo;
import com.smart.model.dtomapper.ProjectEquDtoMapper;
import com.smart.model.domain.ProjectEquDO;
import com.smart.mapper.ProjectEquMapper;
import com.smart.model.request.ProjectEquRequest;
import com.smart.model.util.ProjectEquConvert;
import com.smart.service.ProjectEquService;
import com.smart.model.vo.ProjectEquVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhanghong
 */
@Service
public class ProjectEquServiceImpl extends ServiceImpl<ProjectEquMapper, ProjectEquDO> implements ProjectEquService {
    @Autowired
    private ProjectEquMapper projectEquMapper;

    @Override
    public ProjectEquVO getByKey(long id) {
        ProjectEquDO projectEquDO = getById(id);
        ProjectEquVO projectEquVO = ProjectEquDtoMapper.INSTANCE.do2VO(projectEquDO);
        return projectEquVO;
    }

    @Override
    public PageInfo<ProjectEquVO> pageQuery(ProjectEquRequest request) {
        long count = projectEquMapper.pageCount(request);
        List<ProjectEquDO> list = projectEquMapper.pageQuery(request, request.getPageSize(), request.fetchOffSet());
        List<ProjectEquVO> projectEquVOList = ProjectEquConvert.buildProjectEquVoList(list);
        return new PageInfo(request.getPageNum(), request.getPageSize(), projectEquVOList, count);
    }

    @Override
    public List<ProjectEquVO> listQuery(ProjectEquRequest request) {
        List<ProjectEquDO> list = list();
        List<ProjectEquVO> projectEquVOS = ProjectEquConvert.buildProjectEquVoList(list);
        return projectEquVOS;
    }

    @Override
    public Boolean add(ProjectEquRequest request) {
        ProjectEquDO projectEquDO = ProjectEquDtoMapper.INSTANCE.request2DO(request);
        save(projectEquDO);
        return true;
    }

    @Override
    public Boolean updateByKey(ProjectEquRequest request) {
        ProjectEquDO projectEquDO = ProjectEquDtoMapper.INSTANCE.request2DO(request);
        save(projectEquDO);
        return true;
    }

    @Override
    public Boolean deleteByKey(long id) {
        projectEquMapper.deleteDOById(id);
        return true;
    }
}
